/*******************************************************************************
Replication Materials for Blau, Kahn, Brummund, Cook, and Larson-Koester "Is 
There Still Son Preference in the United States?"

Table R6

Date Modified: 10/19/2019

*******************************************************************************/




*-------------------------------------------------------------------------------
                                   *LOAD DATA
*-------------------------------------------------------------------------------
use "$acs\acs_data", clear


*-------------------------------------------------------------------------------
                               *RESTRICT SAMPLE
*-------------------------------------------------------------------------------
keep if nonusbirth == 0 & multi_sample != 1 & mult == 0 & oldc <=12 & ///
	inrange(age,18,40)==1 & nchild18>=1 & nonrkids == 0 & nonusbirth == 0 ///
	& sfrelate == 0 & father_sample != 1 & female == 1 & foster_hh == 0
drop if citizen == 1 | marst == 5

*-------------------------------------------------------------------------------
                               *AGE AT FIRST BIRTH
*-------------------------------------------------------------------------------
egen max_age = rowmax(c_age*)
sum max_age // should be 12
gen birthage = age - max_age

*-------------------------------------------------------------------------------
                                  *LABELS
*-------------------------------------------------------------------------------

*Label Variables
label var igenfert "Total Fertility"
label var ligengdp "Log of GDP"
label var igenscore "Equity Index"
label var chld1 "First Child Girl"
label var igenlfp "Labor Force Part."
label var igensr "Sex Ratio at Birth"

label var girl_lfp "Girl*Labor Force Part."
label var girl_sr "Girl*Sex Ratio at Birth"
label var girl_ggi "Girl*Equity Index"




*-------------------------------------------------------------------------------
                       *REGRESSIONS, PROB LIVING WITHOUT A FATHER
*-------------------------------------------------------------------------------	
local wgt "hhwtnorm"	
local controls "lths scol cold" //leave out: hsdi
local controls "`controls' i.genrace i.region i.year age age2 age3"
local controls "`controls' yrsusa1 yrsusa2"

// EQUITY
reg femhdalt birthage `controls' igenfert ligengdp igenscore chld1 girl_ggi [aw=`wgt'],  cluster(bpldc)
sum femhdalt if igenscore != . [aw=`wgt']
local mean: display %5.4f r(mean)
outreg2 using "$routput\Table_R6", replace excel dec(4) addtext(Dep. Var. Mean, `mean') keep(igenfert ligengdp igenscore chld1 girl_ggi) ctitle(No Dad) label nocons nor2 ///
	title("Table R6: Table T3, Age at 1st Birth Ctrl")

// LFPR
reg femhdalt birthage `controls' igenfert ligengdp igenlfp chld1 girl_lfp [aw=`wgt'],  cluster(bpldc)
sum femhdalt if igenlfp != . [aw=`wgt']
local mean: display %5.4f r(mean)
outreg2 using "$routput\Table_R6", append excel dec(4) addtext(Dep. Var. Mean, `mean') keep(igenfert ligengdp igenlfp chld1 girl_lfp) ctitle(No Dad) label nocons nor2

// LFPR & SEX RATIO AT BIRTH
reg femhdalt birthage `controls' igenfert ligengdp igenlfp igensr chld1 girl_lfp girl_sr [aw=`wgt'],  cluster(bpldc)
sum femhdalt if igenlfp != . & igensr != . [aw=`wgt']
local mean: display %5.4f r(mean)
outreg2 using "$routput\Table_R6", append excel dec(4) addtext(Dep. Var. Mean, `mean') keep(igenfert ligengdp igenlfp igensr chld1 girl_lfp girl_sr) ctitle(No Dad) label nocons nor2

*-------------------------------------------------------------------------------
                              *REGRESSIONS, FERTILITY
*-------------------------------------------------------------------------------	
local wgt "hhwtnorm"	
local controls "lths scol cold sp_lths sp_scol sp_cold" //leave out: hsdi
local controls "`controls' i.genrace i.sp_genrace i.region i.year age age2 age3" 
local controls "`controls' sp_age sp_age2 sp_age3"
local controls "`controls' yrsusa1 yrsusa2 sp_yrsusa1 sp_yrsusa2 sp_imm igenfert ligengdp"

// SAMPLE
keep if marst == 1

// EQUITY
reg nchild birthage `controls' igenfert ligengdp igenscore chld1 girl_ggi [aw=`wgt'],  cluster(bpldc)
sum nchild if marst == 1 & igenscore != . [aw=`wgt']
local mean: display %5.4f r(mean)
outreg2 using "$routput\Table_R6", append excel dec(4) addtext(Dep. Var. Mean, `mean') keep(igenfert ligengdp igenscore chld1 girl_ggi) ctitle(Fertility) label nocons nor2

// LFPR
reg nchild birthage `controls' igenfert ligengdp igenlfp chld1 girl_lfp [aw=`wgt'],  cluster(bpldc)
sum nchild if marst == 1 & igenlfp != . [aw=`wgt']
local mean: display %5.4f r(mean)
outreg2 using "$routput\Table_R6", append excel dec(4) addtext(Dep. Var. Mean, `mean') keep(igenfert ligengdp igenlfp chld1 girl_lfp) ctitle(Fertility) label nocons nor2

// LFPR & SEX RATIO AT BIRTH
reg nchild birthage `controls' igenfert ligengdp igenlfp igensr chld1 girl_lfp girl_sr [aw=`wgt'],  cluster(bpldc)
sum nchild if marst == 1 & igenlfp != . & igensr != . [aw=`wgt']
local mean: display %5.4f r(mean)
outreg2 using "$routput\Table_R6", append excel dec(4) addtext(Dep. Var. Mean, `mean') keep(igenfert ligengdp igenlfp igensr chld1 girl_lfp girl_sr) ctitle(Fertility) label nocons nor2 sortvar(igenfert ligengdp igenlfp igensr igenscore chld1 girl_lfp girl_sr girl_ggi)
 
